ShortcutKey2URL: 2RINPU
from ShortcutKey2URL自分用
ShortcutKey2URL: 2RINPU
code: script.js
/* デライトの前景一覧または後景一覧のDOMからデータを抽出 */
/* 入力値のエスケープは特にやっていない */
window.DELIGHT = window.DELIGHT ?? {};
window.DELIGHT.inputPrefix = initial => prompt('箇条書きの接頭辞は何にする?', initial) ?? '';
window.DELIGHT.createRinpuText = delimiter => prefix => ...document.querySelectorAll('main article')
.map(bgOrFg => prefix + {${bgOrFg.querySelector('.knm').textContent} ${bgOrFg.getAttribute('data-kno')}})
.join(delimiter);
/* いつもお世話になっているクリップボードコピースニペットを利用 */
window.COPY_TO_CLIPBOARD = window.COPY_TO_CLIPBOARD ?? {};
window.COPY_TO_CLIPBOARD.exec = text => retryCount => {
const textarea = document.createElement('textarea');
textarea.textContent = text;
const body = document.querySelector('body');
body.appendChild(textarea);
textarea.select();
const copied = new Array(1 + retryCount).fill().reduce((prev, curr, i) => {
const count = i + 1;
if (prev) return true;
console.log(Try copying: ${count} time${i?'s':''});
/* 'copy'が機能しないページがあるため'cut'に変更 */
return document.execCommand('cut');
}, false);
body.removeChild(textarea);
return copied;
};
/* 実行 */
window.DELIGHT.copyToClipboard = (DELIGHT, COPY_TO_CLIPBOARD) => (delimiter, initial) => retryCount => {
const prefix = DELIGHT.inputPrefix(initial);
const text = DELIGHT.createRinpuText(delimiter)(prefix);
const result = COPY_TO_CLIPBOARD.exec(text)(retryCount);
alert(コピー${result ? '成功' : '失敗'});
return result;
};
window.DELIGHT.copyToClipboard(window.DELIGHT, window.COPY_TO_CLIPBOARD)('\n', '・')(0);